package fatecmc.interfaces.impl.factory;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import fatecmc.interfaces.IAbstractFactory;
import fatecmc.interfaces.ICommand;
import fatecmc.interfaces.IDAO;

public class ConcreteFactory implements IAbstractFactory {

	Properties propsCommand = new Properties();
	public Properties getPropsCommand() {
		return propsCommand;
	}
	Properties propsDAO = new Properties();
	public Properties getPropsDAO() {
		return propsDAO;
	}
	
	public ConcreteFactory() {
		// TODO Auto-generated constructor stub
		try {
			propsCommand.load(new FileInputStream("./resources/command.properties"));
			propsDAO.load(new FileInputStream("./resources/dao.properties"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@SuppressWarnings("rawtypes")
	@Override
	public ICommand gerarCommand(String strCommand) {
		ICommand command = null;
		String stringClasse = propsCommand.getProperty(strCommand);			
		try {
			Class classe = Class.forName(stringClasse);
			Object object = classe.newInstance();
			command = (ICommand) object;
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}			
		return command;
	
	}
	


	@SuppressWarnings("rawtypes")
	@Override
	public IDAO gerarDAO(String strDAO) {
		IDAO dao = null;
		String stringClasse = propsDAO.getProperty(strDAO);			
		try {
			Class classe = Class.forName(stringClasse);
			Object object = classe.newInstance();
			dao = (IDAO) object;
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}			
		return dao;
	}
}
